﻿using System;
using RaytracerLib.MathLib;
using YAXLib;

namespace RaytracerLib.Volumes
{
    public abstract class SolidVolume : Volume
    {
        protected double m_level_value;
        protected ColorFloat m_level_color;

        public override ColorFloat GetColor(Vector3 a_uvw, Intersection a_intersection)
        {
            return m_level_color;
        }

        public override Tangents GetTangents(Vector3 a_uvw, Vector3 a_tx, Vector3 a_ty,
            Intersection a_intersection)
        {
            throw new NotImplementedException();
        }

        public override double GetValue(Vector3 a_uvw, Intersection a_intersection)
        {
            return m_level_value;
        }
    }

    public class SolidColorVolume : SolidVolume
    {
        public SolidColorVolume(ColorFloat a_color)
        {
            Color = a_color;
        }

        [YAXNode]
        public ColorFloat Color
        {
            get
            {
                return m_level_color;
            }
            set
            {
                m_level_color = value;
                m_level_value = m_level_color.Avg;
            }
        }

        public override void RenderStart(RenderStartPhase a_phase)
        {
            if (a_phase == RenderStartPhase.SRGBToLinear)
                Color = Gamma.SRGBToLinear(Color);

            base.RenderStart(a_phase);
        }
    }

    public class SolidValueVolume : SolidVolume
    {
        public SolidValueVolume(double a_value)
        {
            Value = a_value;
        }

        [YAXNode]
        public double Value
        {
            get
            {
                return m_level_value;
            }
            set
            {
                m_level_value = value;
                m_level_color = new ColorFloat(value);
            }
        }
    }
}